-
-
Notifications
You must be signed in to change notification settings - Fork 881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add parameters to upstream and upstreammembers #1233
Add parameters to upstream and upstreammembers #1233
Conversation
cf49d4c
to
91a8a7b
Compare
@juniorsysadmin Which kind of feedback do you need from me? |
@SaschaDoering Nothing required from you just yet, but given this is a breaking change it would good to get some approval on the design from other users before merging. |
Thanks for the feedback, I thought something was missing from my side :) |
LGTM! :) |
Is the only breaking change the new datatype for |
Yes, this should be the only breaking change. In addition, it is possible to set different values for members of the upstream which is necessary for things like weight. I also don't see a reason for adding extra code for the old method given the README.md states |
sure this is mentioned in the readme and we still didn't do a 1.0.0 release, but still backwards compatibility is always nice. Can you add backwards support or update the READMe.md? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did some inline comments, please have a look. Can you add some acceptance tests so we now this works?
manifests/resource/upstream.pp
Outdated
Enum['http', 'stream'] $upstream_context = 'http', | ||
Enum['present', 'absent'] $ensure = 'present', | ||
Enum['http', 'stream'] $context = 'http', | ||
Optional[Hash] $members = undef, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this default to an empty hash instead of optional? We have some guidelines for datatypes at https://voxpupuli.org/docs/#reviewing-a-module-pr
- Are there new params with datatype Hash or Array? If possible, they should default to empty Hash/Array instead of undef. You can also enforce the datastructure like Array[String]
and:
- If you can supply one or multiple values for an attribute it’s common practice to enforce the datatype for one value and an array of that datatype. An example for string is Variant[String[1],Array[String[1]]]. This can be used in the Puppet code as [$var].flatten()
can you also define the datatypes within the hash?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I'll fix that.
manifests/resource/upstream.pp
Outdated
Optional[String] $members_tag = undef, | ||
Optional[Nginx::UpstreamMemberDefaults] $member_defaults = undef, | ||
Optional[String] $hash = undef, | ||
Optional[Boolean] $ip_hash = undef, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check all parameters with the Boolean
dataype. If it makes sense, remove the Optional
and let them default to True
or False
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, again, I'll fix that, too.
@upstream_cfg_append['keepalive'] = @upstream_cfg_append.delete('keepalive') | ||
-%> | ||
<%- @upstream_cfg_append.each do |key,value| -%> | ||
<% if @hash -%> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I convert upstream_member.erb I will convert this too. It makes no sense to use different templatetypes for one file I think.
@@ -1 +1,12 @@ | |||
server <%= @server %>:<%= @port %> fail_timeout=<%= @upstream_fail_timeout %><% if @upstream_max_fails -%> max_fails=<%=@upstream_max_fails %><% end %>; | |||
server <%= @_server %><% if @params_prepend -%> <%= @params_prepend %><% end -%> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please convert this into an epp template.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll convert the template.
41ccfe2
to
bf8febd
Compare
I pushed a new version a few moments ago which should fix the issues you commented. Please let me know if I missed something, thanks. |
manifests/resource/upstream.pp
Outdated
Optional[Nginx::UpstreamSticky] $sticky = undef, | ||
Optional[Nginx::UpstreamZone] $zone = undef, | ||
Hash $cfg_append = {}, | ||
Hash $cfg_prepend = {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you enforce the datatypes within the hash please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a datatype for this.
manifests/resource/upstream.pp
Outdated
Boolean $ntlm = false, | ||
Optional[Integer] $queue_max = undef, | ||
Optional[Nginx::Time] $queue_timeout = undef, | ||
Optional[String] $random = undef, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For strings, please always use String[1]
, it will enforce a minimal string length of 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fixed.
@@ -0,0 +1,113 @@ | |||
require 'spec_helper_acceptance' | |||
|
|||
describe 'nginx::resource::upstream define:' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
acceptance tests \o/
9d4b426
to
4272747
Compare
4272747
to
aa529c7
Compare
Add parameters to nginx::resource::upstream and nginx::resource::upstream::member which allows more configuration on upstreams as before. The only thing that we broke is that the members of an upstream must now be passed as a hash rather than an array. This also makes the sorting of keepalive to the end no longer necessary because there is now a parameter for it. And values for a nginx::resource::upstream::member can now be set as default for all members of an upstream or individually for each member inside the members hash. Of course, the explicit specification overrides the defaults. In general the changes have made more parameters available to nginx::resource::upstream and nginx::resource::upstream::member. In addition, one of the two templates for nginx::resource::upstream::member was disposed since it is no longer needed. Fixes voxpupuliGH-1222
aa529c7
to
f0bf83a
Compare
I pushed an updated version which fix the datatype issues. So it's your turn again ;) Thanks. |
looks good to me, thanks to the massive PR! I will keep this open so we can get another review from somebody else. |
Ok, thanks for the review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple questions surrounding the changes to the $members
parameter, specifically around how the datatype parses that parameter and if there's another way to do it.
members => { | ||
'localhost:3000': | ||
server => 'localhost' | ||
port => 3000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first glance this can be a little confusing. My first question would be "Why not parse the localhost:3000
into server and port?"
Could we potentially make it an array of hashes so that it looks more like:
nginx::resource::upstream { 'puppet_rack_app':
members => [
{
server => 'localhost',
port => 3000,
},
{
server => 'localhost',
port => 3001,
},
{
server => 'localhost',
port => 3002,
},
]
Does that work or does the parameter rely on each member to have a unique name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mainly cause Unix sockets are accepted too. We would first have to see if it is a valid Unix socket and only if not split at the colon. After that we need to check the parts if they are valid. We almost have to implement the used datatype in code. And at the end we have the problem to name the resources for the defined type which is necessary for exporting upstream members. That's why we need a unique name here.
Should I change the README.md file and use keys that do not consist of server and port? Maybe it's a good idea to use the keys as default for the comment.
Enum['http', 'stream'] $upstream_context = 'http', | ||
Enum['present', 'absent'] $ensure = 'present', | ||
Enum['http', 'stream'] $context = 'http', | ||
Nginx::UpstreamMembers $members = {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above
Is there anything left or any open points to discuss? |
Hey @voxpupuli/collaborators, could I get your feedback here? |
Can we please get this merged or an update what changes should be made? |
order => '90', | ||
content => template('nginx/upstream/upstream_footer.erb'), | ||
content => epp('nginx/upstream/upstream_footer.epp', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My personal preference is for no parameters for epp()
, where possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I highly prefer them, because that allows scoped variables with proper datatypes.
voxpupuli#1233 was a breaking change that amongst other things, renamed this parameter. Fixes voxpupuli#1316
Add parameters to upstream and upstreammembers
voxpupuli#1233 was a breaking change that amongst other things, renamed this parameter. Fixes voxpupuli#1316
Add parameters to upstream and upstreammembers
voxpupuli#1233 was a breaking change that amongst other things, renamed this parameter. Fixes voxpupuli#1316
Pull Request (PR) description
Add parameters to upstream and upstreammembers
Add parameters to nginx::resource::upstream and
nginx::resource::upstream::member which allows more configuration on
upstreams as before. The only thing that we broke is that the
members of an upstream must now be passed as a hash rather than an
array. This also makes the sorting of keepalive to the end no
longer necessary because there is now a parameter for it. And
values for a nginx::resource::upstream::member can now be set as
default for all members of an upstream or individually for each
member inside the members hash. Of course, the explicit
specification overrides the defaults. In general the changes have
made more parameters available to nginx::resource::upstream and
nginx::resource::upstream::member. In addition, one of the two
templates for nginx::resource::upstream::member was disposed since
it is no longer needed.
This Pull Request (PR) fixes the following issues
Fixes GH-1222